package com.gitee.chili.leisure.service.impl;

import com.gitee.chili.leisure.domain.Currency;
import com.gitee.chili.leisure.domain.Innings;
import com.gitee.chili.leisure.repository.InningsRepository;
import com.gitee.chili.leisure.service.IInningsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * InningsService
 *
 * @author week solider
 * @since 2020.09.04
 */
@Slf4j
@Service
public class InningsService implements IInningsService {

    @Autowired
    private InningsRepository inningsRepository;

    @Override
    public InningsRepository getRepository() {
        return inningsRepository;
    }

    public Currency getPay(Integer innings) {

        Optional<Innings> optional = inningsRepository.findOne(Example.of(new Innings().setInnings(innings)));
        return optional.map(Innings::getCurrency).orElse(null);

    }
}
